import java.util.Scanner;

public class Test {
    //输出一个整数的每一位，如：123的每一位是3，2，1
    public static void main1(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个数字：");
        int num = scan.nextInt();
        while(num != 0){
            System.out.println(num % 10);
            num /= 10;
        }
        scan.close();
    }

    //编写代码模拟三次密码输入的场景。
    // 最多能输入三次密码，密码正确，提示“登录成功”,密码错误，可以重新输入，最多输入三次。三次均错，则提示退出程序
    public static void main2_1(String[] args) {
        int rightNum = 31205;
        int count = 3;
        while(count != 0){
            Scanner scan = new Scanner(System.in);
            System.out.println("请输入密码：");
            int num = scan.nextInt();
            if(num == rightNum){
                System.out.println("密码正确！");
                break;
            }else{
                System.out.println("密码错误。");
            }
            count--;
            System.out.println("你还剩 " + count + " 次机会");
        }
    }
    public static void main2_2(String[] args) {
        Scanner scan = new Scanner(System.in);
        int count = 3;
        while(count != 0){
            System.out.println("请输入密码：");
            String pass = scan.nextLine();
            if(pass.equals("huang")){
                System.out.println("密码正确！");
                break;
            }else{
                System.out.println("密码错误。");
            }
            count--;
            System.out.println("你还剩 " + count + " 次机会");
        }
    }

    //求1！+2！+3！+4！+........+n!的和
    public static void main3(String[] args) {
        int ret = 1;
        int sum = 0;
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for (int i = 1; i <= n ; i++) {
            ret = 1;
            for(int j = 1; j <= i; j++){
                ret *= j;
            }
            sum += ret;
        }
        System.out.println(sum);
    }

    //在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值？
    public static int max(int a, int b){
        return Math.max(a,b);
    }
    public static double max(double a, double b, double c){
        return Math.max( Math.max(a,b), c);
    }
    public static void main4(String[] args) {
        int ret1 = max(6,10);
        double ret2 = max(16.9,1.1,96.3);
        System.out.println(ret1);
        System.out.println(ret2);
    }

    //求斐波那契数列的第n项。(迭代实现)
    // 1 1 2 3 5 8 13....
    public static int fib(int n){
        if(n == 1 || n == 2) {
            return 1;
        }
        int f1 = 1;
        int f2 = 1;
        int f3 = 0;
        for (int i = 3; i <= n ; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    public static void main5(String[] args) {
        int ret = fib(7);
        System.out.println(ret);
    }
}